package chapter5;

import static org.junit.Assert.*;

import org.junit.Test;

public class TestGeneraterPrimes {

	@Test
	public void testPrimes(){
		int[] nullArray = PrimeGenerator.generatePrimes(0);
		assertEquals(nullArray.length, 0);
		
		int[] minArray = PrimeGenerator.generatePrimes(2);
		assertEquals(minArray.length, 1);
		assertEquals(minArray[0], 2);
		
		int[] threeArray = PrimeGenerator.generatePrimes(3);
		assertEquals(minArray.length, 2);
		assertEquals(threeArray[0], 2);
		assertEquals(threeArray[0], 3);
		
		int[] centArray = PrimeGenerator.generatePrimes(100);
		assertEquals(centArray.length, 25);
		assertEquals(centArray[24], 97);
	}
	
	public void testExhaustive(){
		for (int i = 0; i < 500; i++) {
			verifyPrimeList(PrimeGenerator.generatePrimes(i));
		}
	}
	
	private static void verifyPrimeList(int[] list){
		for (int i = 0; i < list.length; i++) {
			verifyPrime(list[i]);
		}
	}
	
	private static void verifyPrime(int n){
		for (int factor = 2; factor < n; factor++) {
			assert(n%factor != 0);
		}
	}
}
